﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Reece.Open.Mvc.Atom.Extenders
{
    public static class StringExtenders
    {
        // http://stackoverflow.com/questions/155303/net-how-can-you-split-a-caps-delimited-string-into-an-array
        private static Regex _splitter = new Regex("([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", RegexOptions.Compiled);

        public static string PascalCaseAsWords(this string input)
        {
            return _splitter.Replace(input, "$1 ");
        }

        public static int Count(this string input, string match )
        {
            int count = 0;
            int index = 0;
            while ((index = input.IndexOf(match, index)) != -1)
            {
                ++count;
                index += match.Length;
            }
            return count;
        }
    }
}
